package org.example.sunrise.views;

import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import org.example.sunrise.core.Context;
import org.example.sunrise.core.ViewEnum;
import org.example.sunrise.utils.ButtonUtil;

import java.util.Objects;

public class SimpleMenuView extends AnchorPane {
    private final Context ctx;

    public SimpleMenuView(Context ctx) {
        this.ctx = ctx;
        createView();
    }

    private void createView() {
        ImageView imageView = new ImageView();
        imageView.setImage(new Image(Objects.requireNonNull(SimpleMenuView.class.getResource("defaultMenu/menuScreen.png")).toString()));
        this.getChildren().addAll(imageView, createStart(), createQuit());
    }

    private Button createStart() {
        Button start = ButtonUtil.createMenuTransparentButton(400, 82, 331, 102);
        start.setOnAction(this::start);
        ButtonUtil.setHandCursor(start, ctx.sunriseFactory()::getScene);
        return start;
    }

    private Button createQuit() {
        Button quit = ButtonUtil.createMenuTransparentButton(706, 453, 74, 92);
        quit.setOnAction(this::quit);
        ButtonUtil.setHandCursor(quit, ctx.sunriseFactory()::getScene);
        return quit;
    }

    private void start(ActionEvent evt) {
        ctx.sunriseFactory().show(ViewEnum.GAME);
    }

    private void quit(ActionEvent evt) {
        ctx.sunriseFactory().show(ViewEnum.QUIT);
    }
}
